package api

import (
	"github.com/gin-gonic/gin"
	"homework/global"
	_ "homework/init"
	"homework/intelnal/model"
)

type User struct {
	UserName string `form:"user_name" binding:"required" json:"user_name"`
	Password string `form:"password" binding:"required" json:"password"`
}

func Register(c *gin.Context) {

	//用户注册
	//接值
	//验证格式
	//入库
	var u User

	err := c.ShouldBind(&u)
	if err != nil {
		c.JSON(401, gin.H{"message": "请求参数不正确"})
		return
	}
	user := model.User{
		UserName: u.UserName,
		Password: u.Password,
	}
	err = global.DB.Create(&user).Error
	if err != nil {
		c.JSON(401, gin.H{"message": "注册失败"})
	}
	c.JSON(200, gin.H{"message": "注册成功"})
}
